package com.ymm.lulutong.service.translator;

import com.ymm.lulutong.dto.OrderShipperDTO;
import com.ymm.lulutong.dto.ShowShipperDTO;
import com.ymm.lulutong.entity.Shipper;
import com.ymm.lulutong.request.QueryShipperDTO;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class ShipperTranslator {
    private ShipperTranslator() {
    }

    public static ShowShipperDTO shipper2ShowShipperDTO(Shipper shipper) {
        if (shipper == null) {
            return null;
        }
        ShowShipperDTO showShipperDTO = new ShowShipperDTO();
        showShipperDTO.setShipperId(shipper.getShipperId());
        showShipperDTO.setPhoneNumber(shipper.getPhoneNumber());
        showShipperDTO.setNickname(shipper.getNickname());
        showShipperDTO.setProfilePictureLink(shipper.getProfilePictureLink());
        showShipperDTO.setValid(shipper.getValid());
        showShipperDTO.setVipType(shipper.getVipType());
        showShipperDTO.setVipScore(shipper.getVipScore());
        showShipperDTO.setTotalBalance(shipper.getTotalBalance());
        return showShipperDTO;
    }

    public static OrderShipperDTO shipper2OrderShipperDTO(Shipper shipper) {
        if (shipper == null) {
            return null;
        }
        OrderShipperDTO orderShipperDTO = new OrderShipperDTO();
        orderShipperDTO.setShipperId(shipper.getShipperId());
        orderShipperDTO.setPhoneNumber(shipper.getPhoneNumber());
        orderShipperDTO.setNickname(shipper.getNickname());
        orderShipperDTO.setProfilePictureLink(shipper.getProfilePictureLink());
        return orderShipperDTO;
    }

    public static QueryShipperDTO shipper2QueryShipperDTO(Shipper shipper) {
        if (shipper == null) {
            return null;
        }
        QueryShipperDTO queryShipperDTO = new QueryShipperDTO();
        queryShipperDTO.setShipperName(shipper.getNickname());
        queryShipperDTO.setShipperPhoneNum(shipper.getPhoneNumber());
        queryShipperDTO.setShipperIdNum(String.valueOf(shipper.getShipperId()));
        return queryShipperDTO;
    }

    public static Shipper queryShipperDTO2Shipper(QueryShipperDTO queryShipperDTO) {
        if (queryShipperDTO == null) {
            return null;
        }
        Shipper shipper = new Shipper();
        shipper.setShipperId(Long.valueOf(queryShipperDTO.getShipperIdNum()));
        shipper.setPhoneNumber(queryShipperDTO.getShipperPhoneNum());
        shipper.setNickname(queryShipperDTO.getShipperName());
        return shipper;
    }

    public static List<ShowShipperDTO> listShipper2ListShowShipperDTO(List<Shipper> shippers) {
        List<ShowShipperDTO> showShipperDTOs = new ArrayList<>();
        if (!CollectionUtils.isEmpty(shippers)) {
            shippers.forEach(shipper -> showShipperDTOs.add(shipper2ShowShipperDTO(shipper)));
        }
        return showShipperDTOs;
    }


    public static List<OrderShipperDTO> listShipper2ListOrderShipperDTO(List<Shipper> shippers) {
        List<OrderShipperDTO> orderShipperDTOs = new ArrayList<>();
        if (!CollectionUtils.isEmpty(shippers)) {
            shippers.forEach(shipper -> orderShipperDTOs.add(shipper2OrderShipperDTO(shipper)));
        }
        return orderShipperDTOs;
    }
}
